본문 바로가기
etc

OKTA 최소 셋팅으로 간단하게 체험하기

by debugggggger 2024. 8. 29.

okta developer 페이지에서 가입 및 로그인합니다.

작업진행상 계정문제가 생기면 아래 페이지로 다시 돌아와서 운영자 모드로 진행하면 됩니다.

https://developer.okta.com/login/

 

Okta Developer

 

developer.okta.com

 

 

 

계정 생성

1. 좌측의 Directory-People페이지에서 Add Person 버튼을 클릭합니다.

2. 유저정보를 입력합니다. email이 인증 기준이 될 데이터입니다.

 

Application 생성

dashboard에서 연결할 Application을 생성합니다.

 

1. 좌측의 Applications-Applications 페이지에서 Create App Integration 버튼을 선택합니다.

2. 인증방식은 SAML 2.0로 설정하고 이름을 지정합니다.

 

3. SAML Setting을 진행합니다.

sign-on URL : Application 동작시, 호출할 API의 URL (ex. https://application-domain/api/v1/sso/login)

Audience URI : 인증을 수신받을 경로를 지정합니다.


나머지 설정은 Default로 생성합니다.

 

 

4. 생성이 완료된 후, Applications 탭으로 이동해서 생성한 유저를 Assign합니다.

Assign한 유저의 dash board에 해당 Application이 표시됩니다.

 

로그인 테스트 진행

  1. 우측 상단의 dash board로 이동합니다.

2. 로그아웃후에 테스트 유저로 로그인합니다.

생성한 Application을 클릭하면 로그인 가능한 API로 연결이 됩니다.

API 개발

URL : Application으로 설정한 sign-on URL

Method : POST (고정값)

 

1. Application을 클릭했을때 Body 값으로 base 64 인코딩된 SAML 문자열이 입력됩니다.

{
  "SAMLResponse": "PD94bWwgdmVyc2lvbj0iM...hbWwycDpSZXNwb25zZT4=",
  "RelayState": "https://application-domain"
}

 

2. body의 SAMLResponse값을 base 64로 디코딩하면 XML 형식의 문자열을 확인할 수 있습니다.

전문은 이런 형태입니다.

{
    "?xml": {
        "@_version": "1.0",
        "@_encoding": "UTF-8",
    },
    "saml2p:Response": {
        "saml2:Issuer": {
            "#text": "http://www.okta.com/exke...V5d7",
            "@_Format": "urn:oasis:names:tc:SAML:2.0:nameid-format:entity",
            "@_xmlns:saml2": "urn:oasis:names:tc:SAML:2.0:assertion",
        },
        "ds:Signature": {
            "ds:SignedInfo": {
                "ds:CanonicalizationMethod": {
                    "@_Algorithm": "http://www....4n#",
                },
                "ds:SignatureMethod": {
                    "@_Algorithm": "http://www.w3.org/20...dsig-more#rsa-sha256",
                },
                "ds:Reference": {
                    "ds:Transforms": {
                        "ds:Transform": [
                            {
                                "@_Algorithm": "http://www.w3.org/2000/09/xmldsig#enveloped-signature",
                            },
                            {
                                "@_Algorithm": "http://www.w3.org/2001/10/xml-exc-c14n#",
                            },
                        ],
                    },
                    "ds:DigestMethod": {
                        "@_Algorithm": "http://www.w3.org/2001/04/xmlenc#sha256",
                    },
                    "ds:DigestValue": "8FNAJ9fKGpMgO2Ut...tDZml7Cy9o=",
                    "@_URI": "#id20915...482506293",
                },
            },
            "ds:SignatureValue": "qhTJnfS...ES4uylqaxkTGNs64C8eDeGyw==",
            "ds:KeyInfo": {
                "ds:X509Data": {
                    "ds:X509Certificate": "MIIDqDCCApCg...03HiDtoURg==",
                },
            },
            "@_xmlns:ds": "http://www.w3.org/2000/09/xmldsig#",
        },
        "saml2p:Status": {
            "saml2p:StatusCode": {
                "@_Value": "urn:oasis:na...atus:Success",
            },
            "@_xmlns:saml2p": "urn:oasis:names:tc:SAML:2.0:protocol",
        },
        "saml2:Assertion": {
            "saml2:Issuer": {
                "#text": "http://www.okta.com/exke...V5d7",
                "@_Format": "urn:oasis:name...entity",
                "@_xmlns:saml2": "urn:oasis:...sertion",
            },
            "ds:Signature": {
                "ds:SignedInfo": {
                    "ds:CanonicalizationMethod": {
                        "@_Algorithm": "http://www.w3.org/2001/10/xml-exc-c14n#",
                    },
                    "ds:SignatureMethod": {
                        "@_Algorithm": "http://www.w3.org/2001/04/xmldsig-more#rsa-sha256",
                    },
                    "ds:Reference": {
                        "ds:Transforms": {
                            "ds:Transform": [
                                {
                                    "@_Algorithm": "http://www.w3.org/2000/09/xmldsig#enveloped-signature",
                                },
                                {
                                    "@_Algorithm": "http://www.w3.org/2001/10/xml-exc-c14n#",
                                },
                            ],
                        },
                        "ds:DigestMethod": {
                            "@_Algorithm": "http://www.w3.org/2001/04/xmlenc#sha256",
                        },
                        "ds:DigestValue": "c7DpycUOnqp...bes7Q=",
                        "@_URI": "#id209151...06425",
                    },
                },
                "ds:SignatureValue": "eJHIn4gWp...DVK/tzz54ZQ==",
                "ds:KeyInfo": {
                    "ds:X509Data": {
                        "ds:X509Certificate": "MIIDqDCCApCg...DtoURg==",
                    },
                },
                "@_xmlns:ds": "http://www.w3.org/2000/09/xmldsig#",
            },
            "saml2:Subject": {
                "saml2:NameID": {
                    "#text": "user@email.com",
                    "@_Format": "urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress",
                },
                "saml2:SubjectConfirmation": {
                    "saml2:SubjectConfirmationData": {
                        "@_NotOnOrAfter": "2024-09-10T02:42:32.128Z",
                        "@_Recipient": "https://application-domain/api/v1/sso/login",
                    },
                    "@_Method": "urn:oasis:names:tc:SAML:2.0:cm:bearer",
                },
                "@_xmlns:saml2": "urn:oasis:names:tc:SAML:2.0:assertion",
            },
            "saml2:Conditions": {
                "saml2:AudienceRestriction": {
                    "saml2:Audience": "https://application-domain",
                },
                "@_NotBefore": "2024-09-10T02:32:32.128Z",
                "@_NotOnOrAfter": "2024-09-10T02:42:32.128Z",
                "@_xmlns:saml2": "urn:oasis:names:tc:SAML:2.0:assertion",
            },
            "saml2:AuthnStatement": {
                "saml2:AuthnContext": {
                    "saml2:AuthnContextClassRef": "urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport",
                },
                "@_AuthnInstant": "2024-09-10T02:37:32.127Z",
                "@_SessionIndex": "id172...98",
                "@_xmlns:saml2": "urn:oasis:names:tc:SAML:2.0:assertion",
            },
            "@_ID": "id20...6425",
            "@_IssueInstant": "2024-09-10T02:37:32.127Z",
            "@_Version": "2.0",
            "@_xmlns:saml2": "urn:oasis:names:tc:SAML:2.0:assertion",
        },
        "@_Destination": "https://application-domain",
        "@_ID": "id20915108463432171482506293",
        "@_IssueInstant": "2024-09-10T02:37:32.127Z",
        "@_Version": "2.0",
        "@_xmlns:saml2p": "urn:oasis:names:tc:SAML:2.0:protocol",
    },
}

 

해당 XML 에서 사용할 값은

 

로그인한 유저 이메일 : saml2p:Response > saml2:Assertion > saml2:Subject > saml2:NameID

Audience URI : saml2:Conditions > saml2:AudienceRestriction > saml2:Audience 입니다.

 

3. API단에서 유저 이메일로 유효한 계정인지 판별하고 (삭제유무, 활성계정 유무)

4. 추가로 Audience URI의 값이 올바른 경로를 향하고 있는지 유효성 검사를 추가할 수 있습니다.

    => 이경우에는 서비스 확장 / 도메인 변경등의 이유로 URI값이 바뀔경우, okta와 API config값등을 잘 확인해야합니다.

5. response에 해당 유저에 관한 인증을 추가하고 (ex.Jwt token), Audience URI 경로로 redirect 합니다.

 

'etc' 카테고리의 다른 글

OBS 사용법 - 영상 및 송출경로 설정  (0) 2024.02.19
블로그 개선사항  (0) 2023.03.29