Buscar contenidos

jueves, 21 de febrero de 2019

Pasos para integración con Azure AD, GraphAPI










Home>dev2tenant - App registrations (Preview)>AutenticacionAzureADGraph - Manifest

{
    "id": "cc8f5c11-0494-4af2-b4a9-699f438f1404",
    "acceptMappedClaims": null,
    "accessTokenAcceptedVersion": null,
    "allowPublicClient": null,
    "appId": "0183d6e2-2f4d-48c3-bf68-5876eba118ca",
    "appRoles": [
        {
            "allowedMemberTypes": [
                "User"
            ],
            "description": "Admins can manage roles and perform all task actions.",
            "displayName": "Admin",
            "id": "81e10148-16a8-432a-b86d-ef620c3e48ef",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "value": "Admin"
        },
        {
            "allowedMemberTypes": [
                "User"
            ],
            "description": "Approvers have the ability to change the status of tasks.",
            "displayName": "Approver",
            "id": "fc803414-3c61-4ebc-a5e5-cd1675c14bbb",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "value": "Approver"
        },
        {
            "allowedMemberTypes": [
                "User"
            ],
            "description": "Observers only have the ability to view tasks and their statuses.",
            "displayName": "Observer",
            "id": "fcac0bdb-e45d-4cfc-9733-fbea156da358",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "value": "Observer"
        },
        {
            "allowedMemberTypes": [
                "User"
            ],
            "description": "Writers Have the ability to create tasks.",
            "displayName": "Writer",
            "id": "d1c2ade8-98f8-45fd-aa4a-6d06b947c66f",
            "isEnabled": true,
            "lang": null,
            "origin": "Application",
            "value": "Writer"
        }
    ],
    "oauth2AllowUrlPathMatching": false,
    "createdDateTime": "2019-02-20T20:38:01Z",
    "groupMembershipClaims": "SecurityGroup",
    "identifierUris": [],
    "informationalUrls": {
        "termsOfService": null,
        "support": null,
        "privacy": null,
        "marketing": null
    },
    "keyCredentials": [],
    "knownClientApplications": [],
    "logoUrl": null,
    "logoutUrl": null,
    "name": "AutenticacionAzureADGraph",
    "oauth2AllowIdTokenImplicitFlow": true,
    "oauth2AllowImplicitFlow": true,
    "oauth2Permissions": [],
    "oauth2RequirePostResponse": false,
    "optionalClaims": {
        "idToken": [
            {
                "name": "ctry",
                "source": null,
                "essential": false,
                "additionalProperties": []
            }
        ],
        "accessToken": [
            {
                "name": "ipaddr",
                "source": null,
                "essential": false,
                "additionalProperties": []
            }
        ],
        "saml2Token": [
            {
                "name": "upn",
                "source": null,
                "essential": false,
                "additionalProperties": []
            },
            {
                "name": "extension_ab603c56068041afb2f6832e2a17e237_skypeId",
                "source": "user",
                "essential": false,
                "additionalProperties": []
            }
        ]
    },
    "orgRestrictions": [],
    "parentalControlSettings": {
        "countriesBlockedForMinors": [],
        "legalAgeGroupRule": "Allow"
    },
    "passwordCredentials": [
        {
            "customKeyIdentifier": null,
            "endDate": "2299-12-31T06:00:00Z",
            "keyId": "1c6956c7-34bb-462c-90e4-580d50e29d20",
            "startDate": "2019-02-20T20:40:36.253Z",
            "value": null,
            "createdOn": "2019-02-20T20:42:32.5794059Z",
            "hint": "/|s",
            "displayName": "Password uploaded on Wed Feb 20 2019"
        }
    ],
    "preAuthorizedApplications": [],
    "publisherDomain": "dev2tenant.onmicrosoft.com",
    "replyUrlsWithType": [],
    "requiredResourceAccess": [
        {
            "resourceAppId": "00000003-0000-0000-c000-000000000000",
            "resourceAccess": [
                {
                    "id": "06da0dbc-49e2-44d2-8312-53f166ab848a",
                    "type": "Scope"
                },
                {
                    "id": "5f8c59db-677d-491f-a6b8-5f174b11ec1d",
                    "type": "Scope"
                },
                {
                    "id": "e1fe6dd8-ba31-4d61-89e7-88639da4683d",
                    "type": "Scope"
                },
                {
                    "id": "a154be20-db9c-4678-8ab7-66f6cc099a59",
                    "type": "Scope"
                }
            ]
        }
    ],
    "samlMetadataUrl": null,
    "signInUrl": null,
    "signInAudience": "AzureADMyOrg",
    "tags": [],
    "tokenEncryptionKeyId": null
}






//https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc using (HttpClient client = new HttpClient()) { var username = "wcubero@dev2tenant.onmicrosoft.com "; var password = "$ABC123xyz"; var clientId = "0183d6e2-2f4d-xxx-xxx-xxxx"; var tenandId = "254e256b-76d7-xxx-xxxx-xxxx"; var postData = new FormUrlEncodedContent(new[] { new KeyValuePair<string, string>("username", username), new KeyValuePair<string, string>("password", password), new KeyValuePair<string, string>("grant_type","password"), new KeyValuePair<string, string>("client_secret","/|s+=xxxxxxxx|@u:##b&QLI-_Ya.B}d({Rk((}"), new KeyValuePair<string, string>("scope", $"openid profile"), new KeyValuePair<string, string>("client_id", clientId), new KeyValuePair<string, string>("response_type","token id_token") }); var response = await client.PostAsync(string.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/token",tenandId)/*TenantUrl*/, postData); var responseString = await response.Content.ReadAsStringAsync(); if (response.IsSuccessStatusCode) { var token = JsonConvert.DeserializeAnonymousType( responseString, new { access_token = string.Empty, token_type = string.Empty, expires_in = default(int), refresh_token = string.Empty, id_token = string.Empty }); var jwt = new JwtSecurityToken(token.id_token); var identity = new ClaimsIdentity(jwt.Claims, "password", "name", "role") { BootstrapContext = jwt }; int contador = 1; foreach (var item in identity.Claims) { Console.WriteLine(item.ToString()); contador++; } Console.WriteLine("TotalClaims: "+contador); Console.ReadKey(); } }

miércoles, 13 de febrero de 2019

PureCloud guía para respaldar


https://developer.inindca.com/api/rest/postman.html



Web/Integraciones/OAuth/API Client Admin
Duración Token:       172800
Tipos de Concesión:   Autorización de código
URI Autorizados:      https://www.getpostman.com/oauth2/callback


Generales/Postman/Token
Grant Type:             Authorization Code
Callback URL:           https://www.getpostman.com/oauth2/callback
Auth URL:               https://login.{{environment}}/oauth/authorize
Access Token URL:       https://login.{{environment}}/oauth/token
Client Authentication:  Send as Basic Auth header

gmgservicioscostarica
Client ID:         0aeXXXXXXXXXXXXXXXXXXXXXXXXXXX
Client Secret:     FbXXXXXXXXXXXXXXXXXXXXXXXXXXX


gmgserviciosnicaragua
Client ID:       c99XXXXXXXXXXXXXXXXXXXXXXXXXXXX
Client Secret:   E8XXXXXXXXXXXXXXXXXXXXXXXXXXXX

jueves, 7 de febrero de 2019

A sample application that shows how to call the Azure AD Graph API for an Azure AD B2C directory.




  public static async Task Login_Graph()
        {

            //https://docs.microsoft.com/en-us/azure/active-directory/develop/v2-oauth-ropc

            using (HttpClient client = new HttpClient())
            {
                var username = "xxxx";
                var password = "xxxx";
                var clientId = "xxxx";
                var tenandId = "xxxxx";

                var postData = new FormUrlEncodedContent(new[]
                {
                    new KeyValuePair<string, string>("username", username),
                    new KeyValuePair<string, string>("password", password),
                    new KeyValuePair<string, string>("grant_type","password"),
                    new KeyValuePair<string, string>("client_secret","/|s+=[0@4]t/5_c[q:8!=%!o-=?#[:|@u:##b&QLI-_Ya.B}d({Rk((}"),
                    new KeyValuePair<string, string>("scope", $"openid profile"),
                    new KeyValuePair<string, string>("client_id", clientId),
                    new KeyValuePair<string, string>("response_type","token id_token")
                });

                var response = await client.PostAsync(string.Format("https://login.microsoftonline.com/{0}/oauth2/v2.0/token", tenandId)/*TenantUrl*/, postData);

                var responseString = await response.Content.ReadAsStringAsync();

                if (response.IsSuccessStatusCode)
                {

                    var token = JsonConvert.DeserializeAnonymousType(
                        responseString,
                        new
                        {
                            access_token = string.Empty,
                            token_type = string.Empty,
                            expires_in = default(int),
                            refresh_token = string.Empty,
                            id_token = string.Empty
                        });

                    var jwt = new JwtSecurityToken(token.id_token);

                    var identity = new ClaimsIdentity(jwt.Claims, "password", "name", "role")
                    {
                        BootstrapContext = jwt
                    };

                    int contador = 1;

                    foreach (var item in identity.Claims)
                    {
                        Console.WriteLine(item.ToString());
                        contador++;
                    }

                    Console.WriteLine("TotalClaims: " + contador);

                    Console.ReadKey();
                }

            }

        }

----



How to get Azure API credentials - Client ID, Client Secret, Tenant ID and Subscription ID
https://www.youtube.com/watch?v=WygwzN9FfMQ



https://github.com/AzureADQuickStarts/B2C-GraphAPI-DotNet

A Console application for Azure AD B2C User Management the Azure AD Graph

This sample demonstrates how to perform user management by calling the Azure AD Graph in an automated fashion. This aproach is similar to a service account scenario where the application acts as itself, not as a user that signed-in via an interactive user login. This is done by using the OAuth 2.0 client credentials grant.
The application covered by this sample is a Windows command-line interface (CLI) that allows you to invoke various methods.

Steps to Run

For detailed instructions on how to run this sample, checkout this document.

Questions & Issues

Please file any questions or problems with the sample as a github issue. You can also post on Stackoverflow with the tag azure-ad-b2c.

lunes, 4 de febrero de 2019

Broken Backward Compatibility in System.Web.Http



https://www.c-sharpcorner.com/forums/self-hosting-web-api

https://stackoverflow.com/questions/37207571/broken-backward-compatibility-in-system-web-http


This turned out to be a lot simpler than it looked above. The client side code was the one using the System.Web.Http.SelfHost.HttpSelfHostServer so as a result it was pulling the assembly System.Web.Http.SelfHost.dll into the bin directory.
The unit tests assembly was pulling in System.Web.Http.dll as both it and the server side required it.
The selfhost dll was v4.0.0.0 and the system.web.http was v5.2.3. This is where the problem came from. The fix was to ensure v5.2.3 of System.Web.Http.SelfHost.dll was in the bin directory and add a redirect to the app.config of the unit test assembly.

---

Ankush Band

Ankush Band

  • 1.6k
  • 146
  • 1.6k

self hosting web api

Aug 29 2017 9:46 AM
How to access self hosting web api in windows application from another system through ajax call?
 
when I access self hosted webapi method of windos application from client application through ajax call from another system then it can't access. I explain my self hosted application as follows:
 
I create windows application and it derive from apicontroller it host self in system A with using System.Web.Http.SelfHost dll. following is my code :
 
In Program.cs :
  1. using System;  
  2. using System.Web.Http;  
  3. using System.Web.Http.SelfHost;  
  4. using System.Windows.Forms;  
  5. namespace SelfHost  
  6. {  
  7. static class Program  
  8. {  
  9. [STAThread]  
  10. static void Main(string[] args)  
  11. {  
  12. var config = new HttpSelfHostConfiguration("http://182.150.1.1:8080/api");  
  13. config.Routes.MapHttpRoute(  
  14. name: "API",  
  15. routeTemplate: "{controller}/{action}/{id}",  
  16. defaults: new { id = RouteParameter.Optional }  
  17. );  
  18. using(HttpSelfHostServer server = new HttpSelfHostServer(config))  
  19. {  
  20. server.OpenAsync().Wait();  
  21. Application.EnableVisualStyles();  
  22. Application.SetCompatibleTextRenderingDefault(false);  
  23. Application.Run(new MainForm());  
  24. }  
  25. }  
  26. }  
  27. }  
In ProductsController.cs :
  1. using System.Web.Http;  
  2. namespace SelfHost  
  3. {  
  4. public class ProductsController : ApiController  
  5. {  
  6. MainForm mainForm = new MainForm();  
  7. [HttpPost]  
  8. public IHttpActionResult GetResponse(string message)  
  9. {  
  10. mainForm.TextBoxRequestMsg = message;  
  11. return Json("Response from server successfully with message " + message);  
  12. }  
  13. }  
  14. }  
In MainForm.cs :
  1. using System;  
  2. using System.Windows.Forms;  
  3. namespace SelfHost  
  4. {  
  5. public partial class MainForm : Form  
  6. {  
  7. private string _TextBoxRequestMsg;  
  8. public string TextBoxRequestMsg  
  9. {  
  10. get { return txtReqMsg.Text; }  
  11. set  
  12. {  
  13. _TextBoxRequestMsg = value;  
  14. MessageBox.Show( _TextBoxRequestMsg);  
  15. }  
  16. }  
  17. public MainForm()  
  18. {  
  19. InitializeComponent();  
  20. }  
  21. }  
  22. }  
Following is client application this application and is hosted on another system using this application we can call of self hosted webapi method GetResponse() from another system using jquery Ajax call. Following is my client code:
  1. var message = "test request";  
  2. $.ajax({  
  3. url: 'http://182.150.1.1:8080/api/Products/GetResponse?message=' + message,  
  4. cache: false,  
  5. type: 'POST',  
  6. dataType: 'json',  
  7. contentType: 'application/json; charset=utf-8',  
  8. async: false,  
  9. processData: false,  
  10. success: function (data) {  
  11. alert("Successfully get response.");  
  12. },  
  13. error: function (err) {  
  14. alert("Call to web api failed.");  
  15. }  
  16. });  
Also I stop firewall of both system also I enable inbound rule of "World Wide Web Services (HTTPS Traffic-In)"
 
tell me any possible solutions.

ANSWERS (2)

0
Ankush Band

Ankush Band

  • 1.6k
  • 146
  • 1.6k
Aug 30 2017 7:41 AM
Finally I found solution for above question and I am successfully executed above scenario.
install Microsoft.AspNet.WebApi.Cors
package through NuGet Package Manager
after install this package you can see dll reference System.Web.Http.Cors.dll
and then add the following code in Program.cs for enabling EnableCorsAttribute
as
  
  1. var cors = new EnableCorsAttribute("*""*""*");  
  1. config.EnableCors(cors);  
look like this-
  1. static void Main(string[] args)  
  2. {  
  3. var cors = new EnableCorsAttribute("*""*""*");  
  4. var config = new HttpSelfHostConfiguration("http://192.168.3.81:8080/api");  
  5. config.EnableCors(cors);  
  6. config.Routes.MapHttpRoute(  
  7. name: "API",  
  8. routeTemplate: "{controller}/{action}/{id}",  
  9. defaults: new { id = RouteParameter.Optional }  
  10. );  
  11.   
  12. using(HttpSelfHostServer server = new HttpSelfHostServer(config))  
  13. {  
  14. server.OpenAsync().Wait();  
  15.   
  16. Application.EnableVisualStyles();  
  17. Application.SetCompatibleTextRenderingDefault(false);  
  18.   
  19. Application.Run(new MainForm());  
  20. }  
  21. }  
and then add following attribute in ProductsController.cs
  1. [EnableCors(origins: "*", headers: "*", methods: "*", SupportsCredentials = true)]  
look like this-
  1. namespace SelfHost  
  2. {  
  3. [EnableCors(origins: "*", headers: "*", methods: "*", SupportsCredentials = true)]  
  4. public class ProductsController : ApiController  
  5. {  
  6. MainForm mainForm = new MainForm();  
  7.   
  8. [HttpGet]  
  9. public string GetResponse()  
  10. {  
  11. mainForm.TextBoxRequestMsg = "Request get successfully from client.";  
  12. return "Response from server successfully.";  
  13. }  
  14. }  
  15. }  
in my above question I was told like i have done some settings but actually not required any setting for this.
just give cross domain rights through Microsoft.AspNet.WebApi.Cors package.