2

I make some soft on Unity to our partners. They have their own platform with oauth2 authorization from thier site. I need to realize this logic: Step 1: post to server on auth end-point client_id, redirect_uri, response_type, scope. Step 2: user must authorize in browser with login and pass which are using to enter to their site Step 3: server give me code on redirect uri like this "https://localhost:port/?code="code"", Step 4: I take this code and send to token end-point new form with this code

Trouble is with open tab in browser where user can auth (Step 2) and then go to redirect (Step 3). I tried to Application.OpenURL(www.url);, but after user's auth I see in browser user's private area

I wrote this code, in Debug I have html code of needed page

void Start()
    {
        client_id = "<CLIENTID>";
        client_secret = "<CLIENTSECRET>";
        redirect_uri = "https://localhost:<PORT>";
        StartCoroutine(SendAuthRequest());

    }

    IEnumerator SendAuthRequest()
    {
        path = "http://<URL>/connect/authorize";

        WWWForm form = new WWWForm();
        form.AddField("client_id", client_id);
        //form.AddField("client_secret", client_secret);
        form.AddField("grant_type", "authorization_code");
        form.AddField("redirect_uri", redirect_uri);
        form.AddField("response_type", "code");
        form.AddField("scope", "api");

        WWW wwwRequest = new WWW(path, form.data);
        //UnityWebRequest www =  UnityWebRequest.Post(path, form);

        yield return wwwRequest;

        Debug.Log(wwwRequest.text);
  • Maybe this will help: https://stackoverflow.com/questions/43200124/oauth2-authentication-and-operations-in-unity – Leo Bartkus Apr 02 '19 at 18:54
  • I saw this post but it isn't auth end-point, they send data right away to token end-point – Egor Skvortsov Apr 03 '19 at 10:32
  • Could you rephrase your question a bit? Its hard to understand what you expect to happen and where exactly the issue is – derHugo Apr 03 '19 at 11:57
  • I edited it on the up – Egor Skvortsov Apr 03 '19 at 13:10
  • 1
    If the problem is redirecting to your app, you can use a custom uri scheme or so-called "deep link url". Set `redirect_uri` to your deep link url. You might need to register your deep link url with the oauth identity provider for it to allow redirection to it. From there your app can grab the token off the deep link url using whatever platform specific code does that. Like so: https://www.oauth.com/oauth2-servers/redirect-uris/redirect-uris-native-apps/ – Leo Bartkus Apr 03 '19 at 17:16
  • @EgorSkvortsov, I am jostling with this issue since yesterday, and it turns out I have a working solution to this problem. Though it is a workaround, not an actual solution. If you are interested kindly do let me know, I can share that here. :-) – nIcE cOw Apr 15 '20 at 02:42

0 Answers0